package com.imooc.controller;

import com.imooc.domain.Person;
import com.imooc.domain.Result;
import com.imooc.service.PersonService;
import com.imooc.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created on 2018/3/16.
 *
 * @author zlf
 * @since 1.0
 */
@RestController
@RequestMapping("/api/Customers")
public class PersonController {

    @Autowired
    private PersonService personService;

    @GetMapping
    public List<Person> personList() {
        return personService.findAll();
    }

    @PostMapping
    public Result<Person> girlAdd(Person person) {

        return ResultUtil.success(personService.save(person));
    }

    @PutMapping(value = "/{id}")
    public Result<Person> girlUpdate(@PathVariable("id") Integer id,
                                     Person person) {
        person.setCustomerId(id);
        return ResultUtil.success(personService.save(person));
    }

    @DeleteMapping(value = "/{id}")
    public void girlDelete(@PathVariable("id") Integer id) {
        personService.deltePerson(id);
    }
}
